import { StaffModel } from '../models/staff.js';

export const StaffController = {
  async getAllStaff(req, res) {
    try {
      const staff = await StaffModel.getAllStaff();
      res.json(staff);
    } catch (error) {
      res.status(500).json({ error: 'Failed to fetch staff' });
    }
  },

  async createStaff(req, res) {
    try {
      const id = await StaffModel.createStaff(req.body);
      res.status(201).json({ id, ...req.body });
    } catch (error) {
      res.status(500).json({ error: 'Failed to create staff member' });
    }
  },

  async updateStaff(req, res) {
    try {
      const success = await StaffModel.updateStaff(req.params.id, req.body);
      if (success) {
        res.json({ id: req.params.id, ...req.body });
      } else {
        res.status(404).json({ error: 'Staff member not found' });
      }
    } catch (error) {
      res.status(500).json({ error: 'Failed to update staff member' });
    }
  },

  async deleteStaff(req, res) {
    try {
      const success = await StaffModel.deleteStaff(req.params.id);
      if (success) {
        res.status(204).send();
      } else {
        res.status(404).json({ error: 'Staff member not found' });
      }
    } catch (error) {
      res.status(500).json({ error: 'Failed to delete staff member' });
    }
  }
};